<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of category_model
 * 
 * @author Joydeb Choudhury(mcajoydeb@gmail.com)
 */
class Counter_model extends CI_Model {

    //put your code here


    function __construct() {
        parent::__construct();
        log_message('debug', 'Init Model Initialized');
    }

//--- Count Make or Company------------
    function make_count($type='CAR') {
        $sql = "Select count(*)as total from make where type='$type'";
        $query = $this->db->query($sql);
        $row = $query->row();
        if ($row->total != 0)
            return $row->total;
        else
            return '0';
    }

//--- Count Model by make id------------
    function model_count($type='CAR', $make_id=NULL) {
        if ($make_id) {
            $sql = "Select count(*)as total from model where make_id='$make_id' and type='$type'";
            $query = $this->db->query($sql);
            $row = $query->row();
            if ($row->total != 0)
                return $row->total;
            else
                return '0';
        }
    }

//--- Count Version by model id------------
    function version_count($type='CAR', $model_id=NULL) {
        if ($model_id) {
            $sql = "Select count(*)as total from version where model_id='$model_id' and type='$type'";
            $query = $this->db->query($sql);
            $row = $query->row();
            if ($row->total != 0)
                return $row->total;
            else
                return '0';
        }
    }

//-------Count State by country id------------
    function state_count($country_id=NULL) {
        if ($country_id) {
            $code = trim($country_id);
            $sql = "Select count(*)as total from state where country_id='$code'";
            $query = $this->db->query($sql);
            $row = $query->row();
            if ($row->total != 0)
                return $row->total;
            else
                return '0';
        }
    }

//-------Count City by State id------------
    function city_count($cat_id=NULL) {
        if ($cat_id) {
            $code = trim($cat_id);
            $sql = "Select count(*)as total from city where state_id='$code'";
            $query = $this->db->query($sql);
            $row = $query->row();
            if ($row->total != 0)
                return $row->total;
            else
                return '0';
        }
    }

//------------Count feature group where sl no=0 and type-----------
    function feature_group_count($type=NULL) {
        $sql = "Select count(*) as total from feature where type='$type' and slno='0'";
        $query = $this->db->query($sql);
        $row = $query->row();
        if ($row->total != 0)
            return $row->total;
        else
            return '0';
    }

//------------Count features  where sl no not 0 and type-----------
    function feature_count($type=NULL, $code=NULL) {
        $sql = "Select count(*) as total from feature where slno!=0 and type='$type' and code='$code' ";
        $query = $this->db->query($sql);
        $row = $query->row();
        if ($row->total != 0)
            return $row->total;
        else
            return '0';
    }

//------------Count Specification group where sl no=0 and type-----------
    function specification_group_count($type=NULL) {
        $sql = "Select count(*) as total from specification where type='$type' and slno='0'";
        $query = $this->db->query($sql);
        $row = $query->row();
        if ($row->total != 0)
            return $row->total;
        else
            return '0';
    }

//------------Count Specification  where sl no not 0 and type-----------
    function specification_count($type=NULL, $code=NULL) {
        $sql = "Select count(*) as total from specification where slno!=0 and type='$type' and code='$code' ";
        $query = $this->db->query($sql);
        $row = $query->row();
        if ($row->total != 0)
            return $row->total;
        else
            return '0';
    }

//--------------Count all news----------------
    function news_count() {
        $sql = "Select count(*)as total from news ";
        $query = $this->db->query($sql);
        $row = $query->row();
        if ($row->total != 0)
            return $row->total;
        else
            return '0';
    }

//--------------Count all records from any table depends on status ----------------
    function count_record($tblname='', $status=1) {
        if ($tblname) {
            $sql = "Select count(*)as total from $tblname where  status=$status";
            $query = $this->db->query($sql);
            $row = $query->row();
            if ($row->total != 0)
                return $row->total;
            else
                return 0;
        }else {
            return 0;
        }
    }

//--------------Count all records from any table ----------------    
    function count_all_record($tblname='') {
        if ($tblname) {
            $sql = "Select count(*)as total from $tblname ";
            $query = $this->db->query($sql);
            $row = $query->row();
            if ($row->total != 0)
                return $row->total;
            else
                return 0;
        }else {
            return 0;
        }
    }
    //------------Count pick up group where sl no=0 and type-----------
    function pickup_group_count() {
        $sql = "Select count(*) as total from pickup where slno='0'";
        $query = $this->db->query($sql);
        $row = $query->row();
        if ($row->total != 0)
            return $row->total;
        else
            return '0';
    }

}